<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>login</title>
  <script type="text/javascript" src="js/jquery-3.6.0.js"/>
  <script>
    $(function(){

    })

  </script>
</head>
<link rel="stylesheet" href="css/index.css" type="text/css"/>
<body>
<div class="login-contain">
  <div >
    <div class="form-label">username</div>
    <input class="form-input" type="text" id="username">
  </div>
  <div>
    <div class="form-label">password</div>
    <input class="form-input" type="password" id="password">
  </div>
  <div class="form-link" >
    <a href="register.jsp">register</a>
  </div>
  <div class="form-link">
    <input class="form-button" type="button" value="login" id="loginBtn">
  </div>
</div>

</body>

<script type="text/javascript">
  $(function() {
    $("#loginBtn").click(function() {
      $.ajax({
        type:"post",
        url:"login",
        data:{
          username: $("#username").val(),
          password: $("#password").val(),
        },
        contentType:'application/x-www-form-urlencoded;charset=UTF-8',

        success:function (resp) {
          if (resp === "1"){
            window.location.href = "user/u_index";
          }else if(resp === "-1"){
            alert("The account does not exist");
          } else if (resp === "3"){
            window.location.href = "admin/a.jsp";
          }
          else {
            alert("Wrong account or password");
          }
        }
      })
    })
  })
</script>
</html>